#!/usr/bin/php
<?php
//get the devices
while(42 == 42) {
	$lines = file("/sys/bus/w1/devices/w1_bus_master1/w1_master_slaves");
	for ($i = 0;$i<sizeof($lines); $i++) {
		$lines[$i] = trim($lines[$i]);
		if (!file_exists("/tmp/$lines[$i].pid")) {
			$command = "(/var/www/localhost/htdocs/scripts/readtemp.php $lines[$i] &) > /tmp/$lines[$i].out";
			system($command);			
			sleep(1);
		} else {
			//file is there check the pid
			$fp = fopen("/tmp/$lines[$i].pid","r");
			$line = fread($fp,4096);
			fclose($fp);
			if (file_exists("/proc/$line/cmdline")) {
				$fp = fopen("/proc/$line/cmdline","r");
				$line = fread($fp,4096);
				fclose($fp);
				$line = trim($line);
			} else {
				unlink("/tmp/$lines[$i].pid");
			}
		}
	}
sleep(1);
}
?>
